// Fill out your copyright notice in the Description page of Project Settings.


#include "BaseGM.h"
#include "BasePC.h"
#include "Kismet/GameplayStatics.h"
#include "../MySQL/MySQLSubsystem.h"

ABaseGM::ABaseGM()
{
 		PlayerControllerClass = ABasePC::StaticClass();
		bUseSeamlessTravel=true;

}

void ABaseGM::BeginPlay()
{
	UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(GetWorld());
	GameInstance->GetSubsystem<UMySQLSubsystem>()->JoinDB();
}

void ABaseGM::PostLogin(APlayerController* NewPlayer)
{
	Super::PostLogin(NewPlayer);
	if (Cast<ABasePC>(NewPlayer))
	{
		CurrentlyOnlinePlayers.Add(Cast<ABasePC>(NewPlayer));
	}
}

void ABaseGM::Logout(AController* Exiting)
{
	Super::Logout(Exiting);
	if (Cast<ABasePC>(Exiting))
	{
		CurrentlyOnlinePlayers.Remove(Cast<ABasePC>(Exiting));
	}
}

void ABaseGM::SendChatMessage(FChatMessage ChatMessage)
{
	if (ChatMessage.ChatInfo != "")
	{
		for (auto Player: CurrentlyOnlinePlayers)
		{
			Player->ReceiveChatMessageToC(ChatMessage);
		}
	}
	
	
}
